package com.bjsc.controller.data;

import com.baomidou.mybatisplus.plugins.Page;
import com.bjsc.common.anno.Log;
import com.bjsc.service.IWithdrawService;
import com.bjsc.common.bean.Rest;
import com.bjsc.common.controller.SuperController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author create by VIC.Huang
 * @date 2018/2/7
 */
@Controller
@RequestMapping("/data/withdraw")
public class WithdrawController extends SuperController {
    @Autowired
    private IWithdrawService withdrawService;

    @RequiresPermissions("listWithdraw")
    @RequestMapping("/list/{pageNumber}")
    public String list(@PathVariable Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize, Model model) {
        Page<Map<Object, Object>> page = getPage(pageNumber, pageSize);
        model.addAttribute("pageSize", pageSize);
        Page<Map<Object, Object>> pageData = withdrawService.selectWithdrawPage(page);
        model.addAttribute("pageData", pageData);
        return "data/withdraw/list";
    }

    /**
     * 提现结算
     */
    @Log("提现结算")
    @RequiresPermissions("withdrawSettle")
    @RequestMapping("/settle")
    @ResponseBody
    public Rest settle(Long id){
        withdrawService.settle(id);
        return Rest.ok();
    }

    /**
     * 取消提现结算
     */
    @Log("取消提现结算")
    @RequiresPermissions("withdrawSettle")
    @RequestMapping("/cancelSettle")
    @ResponseBody
    public Rest cancelSettle(Long id){
        withdrawService.cancelSettle(id);
        return Rest.ok();
    }
}
